"""
为文件每行字符串后面加上行号
"""
with open(r"code_IO_file\addLineNumber.txt", "r" ,encoding="utf-8") as f:
    string_list = f.readlines()
    a = [s.rstrip() + "#" + str(number)+"\n" for s, number in
         zip(string_list, range(1, len(string_list) + 1))]  # 回归前面的知识，生成器无法生成元组，所以此处用列表
    print(a)

with open(r"code_IO_file\addLineNumber.txt", "w" ,encoding="utf-8") as f:
    f.writelines(a)